﻿<?php
if (!defined('WEB_ROOT')) { 
	exit;
}


if (isset($_GET['chudeId']) && (int)$_GET['chudeId'] > 0) {
	$chudeId = (int)$_GET['chudeId'];
	$sql2 = " AND t.Chude_id = $chudeId";
	$queryString = "chudeId=$chudeId";
} else {
	$chudeId = 0;
	$sql2  = '';
	$queryString = '';
}

// for paging
// how many rows to show per page
$rowsPerPage = 5;

$sql = "SELECT Tintuc_id, c.Chude_id, c.Chude, Ten, Image
        FROM tbl_tintuc t, tbl_chude c
		WHERE t.Chude_id = c.Chude_id $sql2
		ORDER BY Ten";
$result     = dbQuery(getPagingQuery($sql, $rowsPerPage));
$pagingLink = getPagingLink($sql, $rowsPerPage, $queryString);

$chudeList = buildNewsOptions($chudeId);

?> 
<p>&nbsp;</p>
<form action="processNews.php?action=addNews" method="post"  name="frmListProduct" id="frmListProduct">
 <table width="100%" border="0" cellspacing="0" cellpadding="2" class="text">
  <tr>
   <td align="right">Chủ đề: 
    <select name="cboCategory" class="box" id="cboCategory" onChange="viewProduct();">
     <option selected>Tất cả chủ đề</option>
	<?php echo $chudeList; ?>
   </select>
 </td>
 </tr>
</table>
<br>
 <table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="text">
  <tr align="center" id="listTableHeader"> 
   <td>Tiêu đề</td>
   <td width="75">Hình ảnh</td>
   <td width="75">Chủ đề</td>
   <td width="70">Chỉnh sửa</td>
   <td width="70">Xoá</td>
  </tr>
  <?php
$parentId = 0;
if (dbNumRows($result) > 0) {
	$i = 0;
	
	while($row = dbFetchAssoc($result)) {
		extract($row);
		
		if ($Image) {
			$Image = WEB_ROOT . 'images/tintuc/' . $Image;
		} else {
			$Image = WEB_ROOT . 'images/no-image-small.png';
		}	
		
		
		
		if ($i%2) {
			$class = 'row1';
		} else {
			$class = 'row2';
		}
		
		$i += 1;
?>
  <tr class="<?php echo $class; ?>"> 
   <td><a href="index.php?view=detail&newsId=<?php echo $Tintuc_id; ?>"><?php echo $Ten; ?></a></td>
   <td width="75" align="center"><img src="<?php echo $Image; ?>"></td>
   <td width="75" align="center"><a href="../chude/index.php?chudeId=<?php echo $Chude_id; ?>"><?php echo $Chude; ?></a></td>
   <td width="70" align="center"><a href="javascript:modifyProduct(<?php echo $Tintuc_id; ?>);">Chỉnh sửa</a></td>
   <td width="70" align="center"><a href="javascript:deleteProduct(<?php echo $Tintuc_id; ?>, <?php echo $chudeId; ?>);">Xoá</a></td>
  </tr>
  <?php
	} // end while
?>
  <tr> 
   <td colspan="5" align="center">
   <?php 
echo $pagingLink;
   ?></td>
  </tr>
<?php	
} else {
?>
  <tr> 
   <td colspan="5" align="center">Chưa có tin tức!!</td>
  </tr>
  <?php
}
?>
  <tr> 
   <td colspan="5">&nbsp;</td>
  </tr>
  <tr> 
   <td colspan="5" align="right"><input name="btnAddProduct" type="button" id="btnAddProduct" value="Thêm tin tức" class="box" onClick="addProduct(<?php echo $chudeId; ?>)"></td>
  </tr>
 </table>
 <p>&nbsp;</p>
</form>